<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="window,bat文件,Hexo," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="因为hexo安装在F盘，然后每次要新建blog时，都要先打开到F盘，然后再shift+鼠标右键，点击在此处打开命令行开始新的blog。每次都这样总是略感觉繁琐。这个操作能不能向启动程序一样，在桌面有个快捷方式之类的。想到Windows的bat文件。那就开始试一试 新建blog 首先，我们需要将工作目录定位到F:/blog 然后执行我们的hexo new title命令  下面是编写的命令CD /D">
<meta name="keywords" content="window,bat文件,Hexo">
<meta property="og:type" content="article">
<meta property="og:title" content="bat文件编写总结">
<meta property="og:url" content="https://gitee.com/shuhao/2018/03/13/bat文件编写总结/index.html">
<meta property="og:site_name" content="Niki">
<meta property="og:description" content="因为hexo安装在F盘，然后每次要新建blog时，都要先打开到F盘，然后再shift+鼠标右键，点击在此处打开命令行开始新的blog。每次都这样总是略感觉繁琐。这个操作能不能向启动程序一样，在桌面有个快捷方式之类的。想到Windows的bat文件。那就开始试一试 新建blog 首先，我们需要将工作目录定位到F:/blog 然后执行我们的hexo new title命令  下面是编写的命令CD /D">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-04-23T06:22:34.475Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="bat文件编写总结">
<meta name="twitter:description" content="因为hexo安装在F盘，然后每次要新建blog时，都要先打开到F盘，然后再shift+鼠标右键，点击在此处打开命令行开始新的blog。每次都这样总是略感觉繁琐。这个操作能不能向启动程序一样，在桌面有个快捷方式之类的。想到Windows的bat文件。那就开始试一试 新建blog 首先，我们需要将工作目录定位到F:/blog 然后执行我们的hexo new title命令  下面是编写的命令CD /D">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/shuhao/2018/03/13/bat文件编写总结/"/>





  <title> bat文件编写总结 | Niki </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb9f0585e406f878cb2f29c89ad3cdb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Niki</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天道酬勤</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-categories"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/shuhao/blog/2018/03/13/bat文件编写总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Fang ShuHao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/head.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Niki">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                bat文件编写总结
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-03-13T08:56:53+08:00">
                2018-03-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/bat文件/" itemprop="url" rel="index">
                    <span itemprop="name">bat文件</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>因为hexo安装在F盘，然后每次要新建blog时，都要先打开到F盘，然后再shift+鼠标右键，点击在此处打开命令行开始新的blog。每次都这样总是略感觉繁琐。这个操作能不能向启动程序一样，在桌面有个快捷方式之类的。想到Windows的bat文件。那就开始试一试</p>
<h2 id="新建blog"><a href="#新建blog" class="headerlink" title="新建blog"></a>新建blog</h2><ol>
<li>首先，我们需要将工作目录定位到F:/blog</li>
<li>然后执行我们的hexo new title命令</li>
</ol>
<p>下面是编写的命令<br><figure class="highlight bat"><table><tr><td class="code"><pre><span class="line"><span class="built_in">CD</span> /D F:\</span><br><span class="line"><span class="built_in">cd</span> blog</span><br><span class="line">hexo new <span class="built_in">title</span></span><br></pre></td></tr></table></figure></p>
<p>注：CD切换不同的盘符时需要加上/D</p>
<p>那么问题来了，这个title是我们blog的标题，肯定得是个参数需要传进来。bat文件传参也很方便。在cmd命令下执行bat文件，以空格分隔参数，在bat中%1表示第一个参数，%2表示第二个参数，以此类推。我们来重写下这个命令。<br><figure class="highlight bat"><table><tr><td class="code"><pre><span class="line"><span class="built_in">CD</span> /D F:\</span><br><span class="line"><span class="built_in">cd</span> blog</span><br><span class="line">hexo new %<span class="number">1</span></span><br></pre></td></tr></table></figure></p>
<p>这样创建一个新blog的bat脚本就写好了。(只要肯动手，一切大不同^—-^)。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">之前那个新建blog的命令，必须要在bat文件所在目录下执行，并输入title，不是很方便，今天又查了下bat命令改进了一下，点击bat文件，则文件阻塞，等待输入title然后新增blog。不需要进入bat所在目录 hexo_new.bat &quot;title&quot;这样</span><br><span class="line">其实就是用了set/p这个命令十分简单</span><br><span class="line">```</span><br><span class="line">echo &quot;please input blog title !&quot;</span><br><span class="line">set/p title=</span><br><span class="line">CD /D F:\</span><br><span class="line">cd blog</span><br><span class="line">hexo new %title%</span><br><span class="line">```</span><br><span class="line">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分割线</span><br></pre></td></tr></table></figure>
<p>对于创建完blog文件后，每次要早sublime中去打开文件，感觉甚是烦恼。能不能在创建的脚本中再加个命令，等创建完之后自动在sublime中打开刚才的blog呢？<br>我又去某度上搜了一下，果然，还真有打开程序的命令<strong>start</strong>，所以我只要知道新创建的文件的目录不就行啦，然后又找到了命令%cd%可以获取当前路径。果断在之前脚本下面加了一句<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">echo &quot;please input blog title !&quot;</span><br><span class="line">set/p title=</span><br><span class="line">CD /D F:\</span><br><span class="line">cd blog</span><br><span class="line">hexo new %title%</span><br><span class="line"></span><br><span class="line">start %cd%/source/_posts/%title%.md</span><br></pre></td></tr></table></figure></p>
<p>然而，然而，然而，并没有打开刚才创建的文件，找了半天，发现 hexo new 之后 start的命令没有执行。不行，我又想怎么才能让bat文件执行两条命令呢？问某度，果然有方法：&amp;&amp; 表示命令成功后执行的命令，我又改了一下我的bat<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">echo &quot;please input blog title !&quot;</span><br><span class="line">set/p title=</span><br><span class="line">CD /D F:\</span><br><span class="line">cd blog</span><br><span class="line">hexo new %title% &amp;&amp; start %cd%/source/_posts/%title%.md</span><br></pre></td></tr></table></figure></p>
<p>没错果然可以。</p>
<h2 id="启动Hexo服务"><a href="#启动Hexo服务" class="headerlink" title="启动Hexo服务"></a>启动Hexo服务</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">echo current：%cd%</span><br><span class="line">rem change</span><br><span class="line">CD /D F:\</span><br><span class="line">cd blog</span><br><span class="line">echo current：%cd%</span><br><span class="line">hexo s</span><br></pre></td></tr></table></figure>
<h2 id="发布blog"><a href="#发布blog" class="headerlink" title="发布blog"></a>发布blog</h2><p>因为发布blog分两步：</p>
<ol>
<li>hexo g （hexo generate） 生成blog的静态网页</li>
<li>hexo d（hexo deploy） 部署blog<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">echo &quot;have a good day!&quot;</span><br><span class="line">CD /D F:\</span><br><span class="line">cd blog</span><br><span class="line">hexo g &amp;&amp; hexo d</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>更多关于bat文件编写的命令可<a href="http://blog.csdn.net/daoming1112/article/details/77197558" target="_blank" rel="external">参考</a><br><a href="https://zhidao.baidu.com/question/488934464701039292.html" target="_blank" rel="external">bat文件执行多个命令</a><br><a href="http://www.jb51.net/article/43571.htm" target="_blank" rel="external">start命令介绍</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/window/" rel="tag"># window</a>
          
            <a href="/blog/tags/bat文件/" rel="tag"># bat文件</a>
          
            <a href="/blog/tags/Hexo/" rel="tag"># Hexo</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/03/13/Mongo存储原理/" rel="next" title="Mongo存储原理">
                <i class="fa fa-chevron-left"></i> Mongo存储原理
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/03/13/kafka基本架构/" rel="prev" title="kafka基本架构">
                kafka基本架构 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjY5NS8xMzIzMA=="></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/head.jpg"
               alt="Fang ShuHao" />
          <p class="site-author-name" itemprop="name">Fang ShuHao</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">135</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories">
                <span class="site-state-item-count">35</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">93</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#新建blog"><span class="nav-number">1.</span> <span class="nav-text">新建blog</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#启动Hexo服务"><span class="nav-number">2.</span> <span class="nav-text">启动Hexo服务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#发布blog"><span class="nav-number">3.</span> <span class="nav-text">发布blog</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fang ShuHao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  


  

</body>
</html>
